package training;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_8_16_Training {
    //6 和 9 组成的最大数字
    int maximum69Number(int num) {
        int temp = num;
        int pos = -1;
        int base = 1;

        for (int digit = 0; temp > 0; digit++) {
            if (temp % 10 == 6) {
                pos = base;
            }
            temp /= 10;
            base *= 10;
        }

        if (pos == -1) return num;
        return num + 3 * pos;
    }

    //构成整天的下标对数目 II
    public long countCompleteDayPairs(int[] hours) {
        long[] arr = new long[24];
        for (int x : hours) arr[x % 24]++;
        long res = 0;
        res += (arr[12] - 1) * arr[12] / 2;
        res += (arr[0] - 1) * arr[0] / 2;
        for (int i = 1; i < 12; i++) res += (arr[i] * arr[24 - i]);
        return res;
    }
}
